import {AzraelFrameWorkComponent} from "../Base/AzraelFrameWork";
import ccclass = cc._decorator.ccclass;
import GameFrameworkEntry from "../../src/Base/GameFrameworkEntry";
import {IResourceManager} from "../../src/Resources/IResourceManager";
import GameFrameworkModule from "../../src/Base/GameFrameworkModule";
import ResourceManager from "../../src/Resources/ResourceManager";

@ccclass
export class ResourceComponent extends AzraelFrameWorkComponent{

    private _ResourceManager:IResourceManager & GameFrameworkModule;

    protected onLoad(): void {
        super.onLoad();
        this._ResourceManager = GameFrameworkEntry.GetModule(ResourceManager);
    }

    load<T extends cc.Asset>(paths: string | string[], type: typeof cc.Asset, onComplete: (error: Error, assets: (Array<T> | T)) => void, onProgress?: (finish: number, total: number, item: cc.AssetManager.RequestItem) => void): void {
        this._ResourceManager.load(paths,type,onComplete,onProgress);
    }

    loadTextAsset(paths: string | string[], onComplete: (error: Error, assets: (Array<cc.TextAsset> |  cc.TextAsset)) => void, onProgress?: (finish: number, total: number, item: cc.AssetManager.RequestItem) => void): void {
        this._ResourceManager.loadTextAsset(paths,onComplete,onProgress);
    }

    loadJsonAsset(paths: string | string[], onComplete: (error: Error, assets: (Array<cc.JsonAsset> |  cc.JsonAsset)) => void, onProgress?: (finish: number, total: number, item: cc.AssetManager.RequestItem) => void){
        this._ResourceManager.loadJsonAsset(paths,onComplete,onProgress);
    }
    UnloadAsset(path:string,type:typeof cc.Asset){
        this._ResourceManager.UnloadAsset(path,type);
    }

}